﻿<cfsilent>
	<cfscript>
		
		event.setArg("pageTitle", "教学运行管理 - 排课 - 打印教师课表");
		
		dictAdvice = getProperty("serviceFactory").getBean("senateDictionaryAdvice");
		
		termId = event.getArg("TID");
		depId = event.getArg("DEP");
		
		academicYear = event.getArg("AcademicYear");
		academicTerm = event.getArg("AcademicTerm");
		
		currentTab = event.getArg("TabID", "labDepartment");
		
		rs_ins = queryNew("institute_id");

		rs_teacher = queryNew("tch_id");

		rs_departmentEntity = queryNew("institute_id");
		
		passArgs = structNew();
		
		if ( len(termId) ) {
			
			structInsert(passArgs, "TID", termId);
			
			/* 如果有学期信息传递过来 */
			sql = "	SELECT
						a.institute_id,a.institute_name
					FROM
						t_institute a
					WHERE
						EXISTS(
							SELECT 1 FROM 
								t_teacher_timetable b INNER JOIN t_teacher bt ON bt.tch_id = b.tch_id
							WHERE
								bt.institute_id = a.institute_id
								AND
								b.term_id = :termId 
						)
					ORDER BY
						a.institute_name";
			
			queryObj = new Query(datasource = application.dnsSlave);
			queryObj.addParam(name = "termId", value = termId, cfsqltype = "cf_sql_char");
			rs_ins = queryObj.execute(sql = sql).getResult();
			
			if ( len(depId) ) {
				
				sql = "	SELECT
							i.institute_id,i.institute_name
						FROM
							t_institute i
						WHERE
							i.institute_id = :depID ";
				
				queryObj = new Query(datasource = application.dnsSlave);
				queryObj.addParam(name = "depID", value = depId, cfsqltype = "cf_sql_varchar");
				rs_departmentEntity = queryObj.execute(sql = sql).getResult();
				
				currentTab = "labTeacher";

				sql = "	SELECT
							ttt.tch_id,ttt.tch_name,
							ttttp.tp_series,
							tttte.edu_background,
							SUM(tt.cellrelay) l_sum,
							SUM(CASE WHEN tt.wdidx = '1' THEN tt.cellrelay ELSE 0 END) w1_sum,
							SUM(CASE WHEN tt.wdidx = '2' THEN tt.cellrelay ELSE 0 END) w2_sum,
							SUM(CASE WHEN tt.wdidx = '3' THEN tt.cellrelay ELSE 0 END) w3_sum,
							SUM(CASE WHEN tt.wdidx = '4' THEN tt.cellrelay ELSE 0 END) w4_sum,
							SUM(CASE WHEN tt.wdidx = '5' THEN tt.cellrelay ELSE 0 END) w5_sum,
							SUM(CASE WHEN tt.wdidx = '6' THEN tt.cellrelay ELSE 0 END) w6_sum,
							SUM(CASE WHEN tt.wdidx = '7' THEN tt.cellrelay ELSE 0 END) w7_sum
						FROM
							t_teacher_timetable tt
							INNER JOIN t_teacher ttt ON ttt.tch_id = tt.tch_id
							INNER JOIN t_technical_position ttttp ON ttttp.tp_id = ttt.tp_id
							INNER JOIN t_teacher_educational tttte ON tttte.edu_id = ttt.edu_id
						WHERE
							ttt.institute_id = :depId 
							AND
							tt.term_id = :termId 
						GROUP BY
							ttt.tch_id,ttt.tch_name,
							ttttp.tp_series,
							tttte.edu_background
						ORDER BY
							ttt.tch_name";

				queryObj = new Query(datasource = application.dnsSlave);
				queryObj.addParam(name = "depId", value = depId, cfsqltype = "cf_sql_varchar");
				queryObj.addParam(name = "termId", value = termId, cfsqltype = "cf_sql_char");
				rs_teacher = queryObj.execute(sql = sql).getResult();

			}
		}

	</cfscript>
</cfsilent>

<div id="headArea">
	<div class="uiHeader uiHeaderWithImage ptm">
		<div class="clearfix uiHeaderTop">
			<div class="uiHeaderActions rfloat">
				<a class="uiButton" href="<cfoutput>#buildURL('classCourseTable', passArgs)#</cfoutput>"><i class="mrs img btnList"></i><span class="uiButtonText">行政班课表</span></a>
			</div>
			<div>
				<h2 class="uiHeaderTitle">
					<i class="uiHeaderImage img icon16x16 people"></i>学期教师授课安排情况
				</h2>
			</div>
		</div>
	</div>
</div>

<div class="UIElement">
	<ul class="senateFirstPage">
		<li>
			<div class="clearfix" id="summary">
				
				<cfif termId eq "">
					<!-- termSelector -->
					<cfoutput>#event.getArg("termSelector")#</cfoutput>
					<!-- /termSelector -->
				</cfif>
				
				<cfif len(termId)>
					
					<div class="UItab">
						<div class="tabLables">
							<span <cfif currentTab eq "labDepartment">class="active"</cfif> id="labDepartment" tabTarget="Department">任课单位</span>
							<cfif len(depId)>
								<span <cfif currentTab eq "labTeacher">class="active"</cfif> id="labTeacher" tabTarget="Teacher">教师排课明细</span>
							</cfif>
						</div>
					</div>
					
					<script language="javascript" type="text/javascript">
						//<![CDATA[
						<!--
						$(document).ready(function() {
						
							/* init Tab */
							$("div.tabContent[@id!=' + $targetID + ']").hide();
							$("div#" + $("div.tabLables span.active").attr("tabTarget")).show();
						
							$("div.tabLables > span").click(function(){
								var $targetID = $(this).attr("tabTarget");
							
								$("div.tabLables span").removeClass("active");
								$(this).addClass("active");
							
								$("div.tabContent[@id!=' + $targetID + ']").hide();
								$("div.tabContent#" + $targetID).show();
							});
						
						});
						// -->
						//]]>
					</script>
					
					<div id="Department" class="tabContent">
						
						<div class="noticeBlock">
							<h3>任课教师所在单位</h3>
							<hr/>
						</div>
				
						<div class="clearfix">
							<div class="UICardTable">
                                <cfloop query="rs_ins">
									<cfset structInsert(passArgs, "DEP", rs_ins.institute_id, true) />
									<dl <cfif len(depId) and depId neq rs_ins.institute_id>class="disabled"</cfif>>
										<dt>
											<a href="<cfoutput>#buildURL('teacherArrange', passArgs)#</cfoutput>">
												<b class="school"><!--imgholder--></b>
												<dd>
													<h3><cfoutput>#rs_ins.institute_name#</cfoutput></h3>
												</dd>
											</a>
										</dt>
									</dl>
								</cfloop>
								<!--- 将部门代码回滚为默认值 --->
								<cfif len(depId)>
									<cfset structInsert(passArgs, "DEP", depId, true) />
								</cfif>
							</div>
						</div>

					</div>
					
					<div id="Teacher" class="tabContent">
						
						<cfif rs_departmentEntity.recordCount>
							
							<cfset structInsert(passArgs, "DEP", rs_departmentEntity.institute_id, true ) />
							
							<div class="noticeBlock">
								<div class="operation">
									<a class="uiButton" target="_blank" href="<cfoutput>#buildURL('instituteCoursePrint', passArgs)#</cfoutput>"><i class="mrs img btnPrint"></i><span class="uiButtonText">打印部门教师课表</span></a>
								</div>
								<h3><cfoutput>#rs_departmentEntity.institute_name#</cfoutput></h3>
								<hr/>
							</div>
							
							<cfif rs_teacher.recordCount>
								
								<table class="UIEditable">
									<thead>
										<tr>
											<td width="18"></td>
											<td>工号</td>
											<td>教师</td>
											<td>职称</td>
											<td>学历</td>
											<td>周学时</td>
											<td>一</td>
											<td>二</td>
											<td>三</td>
											<td>四</td>
											<td>五</td>
											<td>六</td>
											<td>日</td>
										</tr>
									</thead>
									<tbody>
									<cfset row = 0 />
                                        <cfloop query="rs_teacher">
											<cfset row++ />
											<cfset structInsert(passArgs, "TCHID", rs_teacher.tch_id, true) />
											<tr class="editRows">
												<td class="index"><cfoutput>#row#</cfoutput></td>
												<td><span class="numeric"><cfoutput>#rs_teacher.tch_id#</cfoutput></span></td>
												<td><a href="<cfoutput>#buildURL('teacherCourseTable', passArgs)#</cfoutput>"><cfoutput>#rs_teacher.tch_name#</cfoutput></a></td>
												<td><cfoutput>#rs_teacher.tp_series#</cfoutput></td>
												<td><cfoutput>#rs_teacher.edu_background#</cfoutput></td>
												<td><span class="numeric"><cfoutput>#rs_teacher.l_sum#</cfoutput></span></td>
												<td><span class="numeric"><cfoutput>#rs_teacher.w1_sum#</cfoutput></span></td>
												<td><span class="numeric"><cfoutput>#rs_teacher.w2_sum#</cfoutput></span></td>
												<td><span class="numeric"><cfoutput>#rs_teacher.w3_sum#</cfoutput></span></td>
												<td><span class="numeric"><cfoutput>#rs_teacher.w4_sum#</cfoutput></span></td>
												<td><span class="numeric"><cfoutput>#rs_teacher.w5_sum#</cfoutput></span></td>
												<td><span class="numeric"><cfoutput>#rs_teacher.w6_sum#</cfoutput></span></td>
												<td><span class="numeric"><cfoutput>#rs_teacher.w7_sum#</cfoutput></span></td>
											</tr>
										</cfloop>
									</tbody>
								</table>
								
							</cfif>
							
						</cfif>
						
					</div>
					
				</cfif>
				
			</div>
		</li>
	</ul>
</div>